package written_examination;
import java.util.*;

public class Main_1125_2 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int t = sc.nextInt();
        int s = t;
        if(t < 0) {
            t = 0;
        }
        for(int i = 1; i < N; i++) {
            t += sc.nextInt();
            s = Math.max(s, t);
            if(t < 0) {
                t = 0;
            }
        }
        System.out.println(s);
    }
}
